import 'package:fluttertoast/fluttertoast.dart' as toast;

enum ToastLength { LENGTH_SHORT, LENGTH_LONG }

enum ToastGravity { TOP, BOTTOM, CENTER }

class Toast {
  static void show(String msg,
      {ToastGravity gravity = ToastGravity.CENTER,
        ToastLength length = ToastLength.LENGTH_SHORT}) {
    int timeInSecondForIos = 0;
    toast.Toast toastLength;
    switch (length) {
      case ToastLength.LENGTH_SHORT:
        timeInSecondForIos = 1;
        toastLength = toast.Toast.LENGTH_SHORT;
        break;
      case ToastLength.LENGTH_LONG:
        timeInSecondForIos = 3;
        toastLength = toast.Toast.LENGTH_LONG;
        break;
    }

    toast.ToastGravity toastGravity;
    switch (gravity) {
      case ToastGravity.TOP:
        toastGravity = toast.ToastGravity.TOP;
        break;
      case ToastGravity.BOTTOM:
        toastGravity = toast.ToastGravity.BOTTOM;
        break;
      case ToastGravity.CENTER:
        toastGravity = toast.ToastGravity.CENTER;
        break;
    }

    toast.Fluttertoast.cancel();

    toast.Fluttertoast.showToast(
      msg: msg,
      gravity: toastGravity,
      toastLength: toastLength,
      timeInSecForIosWeb: timeInSecondForIos,
    );
  }

  static void showImportant(String msg) {
    show(msg, gravity: ToastGravity.CENTER, length: ToastLength.LENGTH_LONG);
  }
}
